
if (sessionStorage.getItem('adminID')){

}else {
    alert('无权限');
    window.location.href='Login_Custom.html';
}

window.onload=function (){

    function chooseRoomNameById(roomId){
        if (roomId==5){
            return "特惠标准间";
        }else if (roomId==6){
            return "雅居大床房";
        }
        else if (roomId==7){
            return "私人观影房";
        }
        else if (roomId==8){
            return "迷你单人间";
        }
        else if (roomId==9){
            return "情侣大床房";
        }
        else if (roomId==10){
            return "行政标准间";
        }
        else if (roomId==11){
            return "娱乐棋牌房";
        }else {
            return "亲子房";
        }
    }
    var trueReserList=[];

    axios({
        method: 'get',
        url: '/ReservationController/selectRoomIdIsNull'
    }).then(function (resp) {
        if (resp){

            var result=resp.data.data;
            var tbody=document.querySelector("#userinfo");
            for (var i=0;i<result.length;i++){
                var td1=document.createElement("td");
                var td2=document.createElement("td");
                var td3=document.createElement("td");
                var td4=document.createElement("td");
                var td5=document.createElement("td");
                td1.innerHTML=i+1;
                td2.innerHTML=result[i].id;
                td3.innerHTML=result[i].roomLevelID+' '+chooseRoomNameById(result[i].roomLevelID);
                td4.innerHTML=result[i].arriveTime;
                td5.innerHTML=result[i].predetermineDay;
                var tr=document.createElement('tr');
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tbody.appendChild(tr);
                trueReserList.push(result[i].id);
            }

        }else {
        }
    });

    var btn=document.querySelector("#axiosbtn");
    btn.onclick=function () {
        var rid = document.querySelector("#rid").value;
        var rnum = document.querySelector("#rnum").value;
        //console.log(rid+' '+rnum);
        var flagTrueRoom=false;
        for (var i=0;i<trueReserList.length;i++){
            if (rid==trueReserList[i]){
                flagTrueRoom=true;
            }
        }

        axios({
            method: 'put',
            url: '/ReservationController/updateroomID/'+rid+'/'+rnum,
        }).then(function (resp) {
            if (flagTrueRoom){
            //    TODO 修改room房间状态
                axios({
                    method: 'put',
                    url: '/RoomController/updateroomStateone/'+rnum
                }).then(function (resp) {
                    if (flagTrueRoom){
                        alert("已完成对订单"+rid+"的房间安排");
                        location.reload();
                    }
                    else {
                        alert("请检查！安排失败了");
                        location.reload();
                    }
                });

            }
            else {
                alert("请检查！安排失败了");
            }
        });
    }
}